<?php 
header("content-type:text/html;charset=utf8");
$goods_id = $_GET['goods_id'];
$redis = new Redis();$redis->connect('127.0.0.1','6379');
$pdo = new PDO("mysql:host=127.0.0.1;charset=utf8;dbname=liu",'root','root');
//$num = $redis->lrange('num',0,-1);

if ($redis->lpop('goods_'.$goods_id)) {
	$res = $pdo->exec("update hot_goods set nummber=nummber-1 where goods_id=$goods_id");
	if ($res) {
		$arr = array('code'=>1,'msg'=>"抢购成功");
	}
}
else{
	$arr = array('code'=>0,'msg'=>"抢购失败");
	$data = $pdo->query("select nummber from hot_goods where goods_id =$goods_id")->fetch(PDO::FETCH_ASSOC);
	for ($i=1; $i <=$data['nummber']; $i++) { 
		$redis->lpush('goods_'.$goods_id,$i);
	}
}
echo json_encode($arr);


















 ?>